﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace nplJobsDAL.Delete
{
    public class DeleteJobAlert : DataAccessBase
    {
        public bool IsDeleted { get; set; }
        public long JobAlertID { get; set; }
        public Guid JobSeekerId { get; set; }
        public DeleteJobAlert()
        {
            StoredProcedureName = StoredProcedure.Name.spDeleteJobAlertByJobSeeker.ToString();
        }

        public void invoke()
        {
            DeleteJobAlertParameters deleteJobAlertParameters = new DeleteJobAlertParameters(JobAlertID, JobSeekerId);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = deleteJobAlertParameters.Parameters;
            dbHelper.RunScalar();

            if (deleteJobAlertParameters.Parameters[1].Value != null)
            {
                IsDeleted = bool.Parse(deleteJobAlertParameters.Parameters[2].Value.ToString());
            }
        }
    }

    internal class DeleteJobAlertParameters
    {
        public bool isDeleted = false;
        public long JobAlertID { get; set; }
        public Guid JobSeekerId { get; set; }

        public DeleteJobAlertParameters(long JobAlertID, Guid JobSeekerId)
        {
            this.JobAlertID = JobAlertID;
            this.JobSeekerId = JobSeekerId;
            Build();
        }

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobAlertID", this.JobAlertID),
                    new SqlParameter("@JobSeekerId", this.JobSeekerId),
                    new SqlParameter("@IsDeleted",isDeleted){ Direction =System.Data.ParameterDirection.Output}
                };

            Parameters = parameters;
        }

        public SqlParameter[] Parameters { get; set; }
    }
}
